# 导入包
from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep
# 1.导入鼠标操作类
from selenium.webdriver.common.action_chains import ActionChains
# 获取浏览器驱动
driver = webdriver.Firefox()
driver.maximize_window()
# 打开测试的页面
url = 'file:///root/NSD2408/html/drop.html'
driver.get(url)
# 2.创建鼠标操作对象
action = ActionChains(driver)
# 定位元素
div1 = driver.find_element(By.CSS_SELECTOR, '#div1')
div2 = driver.find_element(By.CSS_SELECTOR, '#div2')
# 3.将源元素拖拽到目标元素位置
sleep(3)
action.drag_and_drop(div1, div2).perform()

sleep(3)
# 4.将元素按照偏移量进行拖拽
action.drag_and_drop_by_offset(div2, xoffset=500, yoffset=400).perform()

# 关闭浏览器
sleep(3)
driver.quit()